package com.xiao.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author xiaoxiaoping
 * @Date 2020/9/14 14:58
 * @Version 1.0
 */
@Service
public class PaymentService {
	public String  paymentInfo_ok(Integer id){
		return "线程池： "+Thread.currentThread().getName()+"  paymentInfo_ok id: "+id+"\t"+"O(∩_∩)O哈哈~";
	}
	
	@HystrixCommand(fallbackMethod = "paymentInfo_timeout_handler",commandProperties = {
			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "5000")
	})
	public String  paymentInfo_timeout(Integer id){
		int time = 3;
		//int time = 10/0;
		try {
			TimeUnit.SECONDS.sleep(time);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "线程池： "+Thread.currentThread().getName()+"  paymentInfo_timeout id: "+id+"\t"+"O(∩_∩)O哈哈~"+" 耗时（秒）"+time;
	}
	
	public String paymentInfo_timeout_handler(Integer id){
		return "线程池： "+Thread.currentThread().getName()+"  paymentInfo_timeout_handler id: "+id+"\t"+"超时或异常了！";
	}
}
